<template>
  <nav-bar class="nav-bar">
    <div slot="left" class="left" @click="retuClick">
      <img src="~assets/img/common/back.svg" alt />
    </div>

    <div slot="center" class="title">
      <div
        v-for="(item,index) in titles"
        :key="index"
        class="title-item"
        @click="clickTitle(index)"
        :class="{active:index === currentIndex}"
      >{{item}}</div>
    </div>
  </nav-bar>
</template>

<script>
import NavBar from 'components/common/navbar/NavBar'
export default {
  name: 'DetailNavBar',
  components: {
    NavBar
  },
  data () {
    return {
      titles: ['商品', '参数', '评论', '推荐'],
      currentIndex: 0
    }
  },
  methods: {
    // 点击左箭头 返回上一页 go(-1) 等同于back()
    retuClick () {
      this.$router.go(-1)
    },
    // 点击导航高亮
    clickTitle (index) {
      this.currentIndex = index
      this.$emit('clickTitle', index)
    }
  }

}
</script>

<style scoped>
.title {
  display: flex;
  font-size: 16px;
}
.title-item {
  flex: 1;
}
.left {
  margin-top: 6px;
}
.left img {
  width: 20px;
  height: 20px;
}

.nav-bar {
  position: relative;
  background-color: #fff;
  z-index: 100;
}

.active {
  color: var(--color-high-text);
}
</style>
